﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.RestaurantArea
{
    public class RestaurantAreaPresenter : Presenter<IRestaurantAreaView>
    {
        public RestaurantAreaPresenter(IRestaurantAreaView view)
            : base(view)
        {
        }

        public void Display(string restaurantAreaId)
        {
            if (restaurantAreaId == null) return;

            var restaurantArea = Model.GetRestaurantArea(restaurantAreaId);

            View.RestaurantAreaID = restaurantArea.RestaurantAreaID;
            View.RestaurantAreaCode = restaurantArea.RestaurantAreaCode;
            View.RestaurantAreaName = restaurantArea.RestaurantAreaName;
            View.RestaurantID = restaurantArea.RestaurantID;
            View.Description = restaurantArea.Description;
            View.IsActive = restaurantArea.IsActive;
        }

        public int Save()
        {
            var restaurantArea = new RestaurantAreaModel
            {
                RestaurantAreaID = View.RestaurantAreaID,
                RestaurantAreaCode = View.RestaurantAreaCode,
                RestaurantAreaName = View.RestaurantAreaName,
                RestaurantID = View.RestaurantID,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (View.RestaurantAreaID == null)
                return Model.AddRestaurantArea(restaurantArea);
            else
                return Model.UpdateRestaurantArea(restaurantArea);
        }

        public int Delete(string restaurantAreaId)
        {
            return Model.DeleteRestaurantArea(restaurantAreaId);
        }
    }
}
